﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zocono.WCS.Domain.PlcBytesObject
{
    public class PlanarGeneralWriteWcsAction : WriteByteObjectBase
    {
        public PlanarGeneralWriteWcsAction() { }
        public PlanarGeneralWriteWcsAction(long plcConnectionID
            , long plcWriteDbID
            , int dbCode
            , int dbStart
            , string objectType
            , int equipmentCode
            , short actionType
            , int toEquipmentCode
            , int taskCode
            , string palletBarcode
            , byte palletType
            , byte alrmCode
            , byte reserve = 0
            , byte reserve2 = 0
            , byte reserve3 = 0
            , byte reserve4 = 0)
        {
            PlcConnectionID = plcConnectionID;
            PlcWriteDbID = plcWriteDbID;
            DbCode = dbCode;
            DbStart = dbStart;
            ObjectType = objectType;
            EquipmentCode = equipmentCode;
            ActionType = actionType;
            ToEquipmentCode = toEquipmentCode;
            TaskCode = taskCode;
            PalletBarcode = palletBarcode;
            PalletType= palletType;
            AlrmCode = alrmCode;
            Reserve = reserve;
            Reserve2 = reserve2;
            Reserve3 = reserve3;
            Reserve4 = reserve4;
        }

        /// <summary>
        /// 握手类型 
        /// </summary>
        public short ActionType { get; set; }
        /// <summary>
        /// 目标位置编号
        /// </summary>
        public int ToEquipmentCode { get; set; }
        /// <summary>
        /// 任务号
        /// </summary>
        public int TaskCode { get; set; }
        /// <summary>
        /// 托盘条码
        /// </summary>
        public string PalletBarcode { get; set; }
        /// <summary>
        /// 空托满托
        /// </summary>
        //public short IsFull { get; set; }
        public byte PalletType { get; set; }
        public byte AlrmCode { get; set; }
        /// <summary>
        /// 预留
        /// </summary>
        public byte Reserve { get; set; }
        public byte Reserve2 { get; set; }
        public byte Reserve3 { get; set; }
        public byte Reserve4 { get; set; }

        public override byte[] Deserialize()
        {
            byte[] bytes = new byte[40];
            //HelperByte.SetByteAt(bytes, 0, 6);
            //byte length = Convert.ToByte(EquipmentCode.ToString().Length);
            //HelperByte.SetByteAt(bytes, 1, length);
            HelperByte.SetDIntAt(bytes, 0, EquipmentCode);
            HelperByte.SetDIntAt(bytes, 4, TaskCode);
            //HelperByte.SetByteAt(bytes,12, 12);
            //length = Convert.ToByte(ToEquipmentCode.ToString().Length);
            //HelperByte.SetByteAt(bytes, 13, length);
            HelperByte.SetDIntAt(bytes, 8, ToEquipmentCode);
            HelperByte.SetByteAt(bytes, 12, 18);
            byte length = Convert.ToByte(PalletBarcode.Length);
            HelperByte.SetByteAt(bytes, 13, length);
            HelperByte.SetCharsAt(bytes, 14, PalletBarcode);
            //HelperByte.SetIntAt(bytes, 40, IsFull);
            HelperByte.SetIntAt(bytes, 32, ActionType);
            HelperByte.SetByteAt(bytes, 34, PalletType);
            HelperByte.SetByteAt(bytes, 35, AlrmCode);
            HelperByte.SetByteAt(bytes, 36, Reserve);
            HelperByte.SetByteAt(bytes, 37, Reserve2);
            HelperByte.SetByteAt(bytes, 38, Reserve3);
            HelperByte.SetByteAt(bytes, 39, Reserve4);

            return bytes;
        }

    }
}
